package com.jy.rhin.facade.controller.audit;


import com.jy.framework.base.entity.Page;
import com.jy.framework.base.entity.Result;
import com.jy.rhin.application.assembler.AuditAssembler;
import com.jy.rhin.application.basic.AuditService;
import com.jy.rhin.facade.dto.SaveExternalSystemAuditInfoEvent;
import com.jy.rhin.infra.repo.audit.query.AuditInfoQueryHandler;
import com.jy.rhin.sdk.dto.audit.AuditDto;
import com.jy.rhin.sdk.dto.audit.AuditInfoReqDto;
import com.jy.rhin.sdk.dto.audit.AuditInfoRespDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @Description:
 * @Author: lww
 * @Date: 2022/5/19 11:52
 */
@RestController
@RequestMapping("/audit")
@Api(tags = "安全审计服务")
@Slf4j
public class AuditBizController {
    @Resource
    AuditInfoQueryHandler auditInfoQueryHandler;
    @Resource
    AuditService auditService;

    @ApiOperation("分页查询审计记录")
    @GetMapping("/listAuditInfo")
    public Result<Page<AuditInfoRespDto>> listAuditInfo(AuditInfoReqDto dto) {
        return Result.success(auditInfoQueryHandler.selectByPage(dto));
    }

    @ApiOperation("获取审计记录")
    @GetMapping("/getAuditInfo")
    public Result<AuditDto> getAuditInfo(Long id) {
        return Result.success(AuditAssembler.convertEnum(auditInfoQueryHandler.getById(id)));
    }

    @ApiOperation("保存第三方审计日志")
    @PostMapping("/addAuditInfo4ExternalSystem")
    public Result addAuditInfo4ExternalSystem(@RequestBody  @Valid  SaveExternalSystemAuditInfoEvent event) {
        auditService.addAuditLog4ExternalSystem(event);
        return Result.success();
    }

}
